package com.stylefeng.guns.rest.modular.film.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.stylefeng.guns.api.film.*;
import com.stylefeng.guns.rest.common.persistence.dao.*;
import com.stylefeng.guns.rest.common.persistence.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName FilmServiceImpl
 * @Description TODO
 * @Author zhaoluowei
 * @Date 2019/9/13  20:47
 * @Version 1.0
 */
@Component
@Service(interfaceClass = FilmAsyncServiceApi.class)
public class FilmAsyncServiceImpl implements FilmAsyncServiceApi {

    @Autowired
    private MoocFilmInfoTMapper moocFilmInfoTMapper;

    @Autowired
    private MoocActorTMapper moocActorTMapper;


    @Override
    public FilmDesVo getFilmDes(String filmId) {
        MoocFilmInfoT moocFilmInfoT = getMoocFilmInfoT(filmId);

        FilmDesVo filmDesVo = new FilmDesVo();
        filmDesVo.setBiography(moocFilmInfoT.getBiography())
                .setFilmId(moocFilmInfoT.getFilmId());
        return filmDesVo;
    }

    @Override
    public ImgVo getImgs(String filmId) {
        MoocFilmInfoT moocFilmInfoT = getMoocFilmInfoT(filmId);
        String[] filmImgs = moocFilmInfoT.getFilmImgs().split(",");

        ImgVo imgVo = new ImgVo();
        imgVo.setMainImg(filmImgs[0]);
        imgVo.setImg01(filmImgs[1]);
        imgVo.setImg02(filmImgs[2]);
        imgVo.setImg03(filmImgs[3]);
        imgVo.setImg04(filmImgs[4]);

//        for (int i = 1; i < filmImgs.length; i++) {
//
//        }
        return imgVo;
    }

    @Override
    public ActorVo getDectInfo(String filmId) {
        MoocFilmInfoT moocFilmInfoT = getMoocFilmInfoT(filmId);

        //获取导演
        Integer directorId = moocFilmInfoT.getDirectorId();

        MoocActorT moocActorT = moocActorTMapper.selectById(directorId);

        ActorVo actorVo = new ActorVo();
        actorVo.setDirectorName(moocActorT.getActorName())
                .setImgAddress(moocActorT.getActorImg());

        return actorVo;
    }

    @Override
    public List<ActorVo> getActors(String filmId) {
        //List<ActorVo> actorVos = new ArrayList<>();
        //actorVos.clear();

        List<ActorVo> actors = moocActorTMapper.getActors(filmId);


        return actors;
    }


    //处理数据的方法
    private MoocFilmInfoT getMoocFilmInfoT(String filmId) {
        MoocFilmInfoT moocFilmInfoT = new MoocFilmInfoT();
        moocFilmInfoT.setFilmId(filmId);

        moocFilmInfoT = moocFilmInfoTMapper.selectOne(moocFilmInfoT);

        return moocFilmInfoT;
    }


}
